package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TenderExpertexpertGroupMapper;
import com.ruoyi.system.domain.TenderExpertexpertGroup;
import com.ruoyi.system.service.ITenderExpertexpertGroupService;
import com.ruoyi.common.core.text.Convert;

/**
 * 专家组管理Service业务层处理
 *
 * @author ruoyi
 * @date 2025-05-12
 */
@Service
public class TenderExpertexpertGroupServiceImpl implements ITenderExpertexpertGroupService {
    @Autowired
    private TenderExpertexpertGroupMapper tenderExpertexpertGroupMapper;
    @Autowired
    private SysUserServiceImpl sysUserService;

    /**
     * 查询专家组管理
     *
     * @param groupId 专家组管理主键
     * @return 专家组管理
     */
    @Override
    public TenderExpertexpertGroup selectTenderExpertexpertGroupByGroupId(Long groupId) {
        return tenderExpertexpertGroupMapper.selectTenderExpertexpertGroupByGroupId(groupId);
    }

    @Override
    public List<TenderExpertexpertGroup> selectTenderExpertexpertGroupAll() {
        return tenderExpertexpertGroupMapper.selectTenderExpertexpertGroupAll();
    }

    /**
     * 查询专家组管理列表
     *
     * @param tenderExpertexpertGroup 专家组管理
     * @return 专家组管理
     */
    @Override
    public List<TenderExpertexpertGroup> selectTenderExpertexpertGroupList(TenderExpertexpertGroup tenderExpertexpertGroup) {
        List<TenderExpertexpertGroup> tenderExpertexpertGroups = tenderExpertexpertGroupMapper.selectTenderExpertexpertGroupList(tenderExpertexpertGroup);

        for (TenderExpertexpertGroup expertexpertGroup : tenderExpertexpertGroups) {
            List<String> names = new ArrayList<String>();
            String[] split = expertexpertGroup.getExpertList().split(",");
            for (String s : split) {
                SysUser sysUser = sysUserService.selectUserById(Long.parseLong(s));
                names.add(sysUser.getUserName());
            }
            StringUtils.join(names, ",");
            expertexpertGroup.setExpertList(names.toString());
        }

        return tenderExpertexpertGroups;
    }

    /**
     * 新增专家组管理
     *
     * @param tenderExpertexpertGroup 专家组管理
     * @return 结果
     */
    @Override
    public int insertTenderExpertexpertGroup(TenderExpertexpertGroup tenderExpertexpertGroup) {
        return tenderExpertexpertGroupMapper.insertTenderExpertexpertGroup(tenderExpertexpertGroup);
    }

    /**
     * 修改专家组管理
     *
     * @param tenderExpertexpertGroup 专家组管理
     * @return 结果
     */
    @Override
    public int updateTenderExpertexpertGroup(TenderExpertexpertGroup tenderExpertexpertGroup) {
        return tenderExpertexpertGroupMapper.updateTenderExpertexpertGroup(tenderExpertexpertGroup);
    }

    /**
     * 批量删除专家组管理
     *
     * @param groupIds 需要删除的专家组管理主键
     * @return 结果
     */
    @Override
    public int deleteTenderExpertexpertGroupByGroupIds(String groupIds) {
        return tenderExpertexpertGroupMapper.deleteTenderExpertexpertGroupByGroupIds(Convert.toStrArray(groupIds));
    }

    /**
     * 删除专家组管理信息
     *
     * @param groupId 专家组管理主键
     * @return 结果
     */
    @Override
    public int deleteTenderExpertexpertGroupByGroupId(Long groupId) {
        return tenderExpertexpertGroupMapper.deleteTenderExpertexpertGroupByGroupId(groupId);
    }
}
